
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 01/17/2012 11:33:12
-- Generated from EDMX file: E:\02 Study\01 Project项目\06 良信餐饮\02 SourceCode\01 SourceCode\Resto.CostControl.Core\Domain\Model\RestoCost.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [RestoCost];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Rel_Material_MaterialStorageHistory]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MaterialStorageHistory] DROP CONSTRAINT [FK_Rel_Material_MaterialStorageHistory];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_RawMaterial_SemiMaterial]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Material_SemiMaterial] DROP CONSTRAINT [FK_Rel_RawMaterial_SemiMaterial];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_Dish_MaterialDish]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DishMaterial] DROP CONSTRAINT [FK_Rel_Dish_MaterialDish];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_Material_DishMaterial]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DishMaterial] DROP CONSTRAINT [FK_Rel_Material_DishMaterial];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_Dish_WeekDishItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WeekDishItem] DROP CONSTRAINT [FK_Rel_Dish_WeekDishItem];
GO
IF OBJECT_ID(N'[dbo].[FK_WeekDishItemWeekDish]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WeekDishItem] DROP CONSTRAINT [FK_WeekDishItemWeekDish];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_Dish_DishOrderItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DishOrderItem] DROP CONSTRAINT [FK_Rel_Dish_DishOrderItem];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_DishOrder_DishOrderItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DishOrderItem] DROP CONSTRAINT [FK_Rel_DishOrder_DishOrderItem];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_Site_DishOrder]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DishOrder] DROP CONSTRAINT [FK_Rel_Site_DishOrder];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_Site_WeekDishOrder]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WeekDishOrder] DROP CONSTRAINT [FK_Rel_Site_WeekDishOrder];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_WeekDishOrder_DishOrder]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DishOrder] DROP CONSTRAINT [FK_Rel_WeekDishOrder_DishOrder];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_DishDeliveryItem_Material]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DishDeliveryItem] DROP CONSTRAINT [FK_Rel_DishDeliveryItem_Material];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_Site_SiteIncome]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SiteIncome] DROP CONSTRAINT [FK_Rel_Site_SiteIncome];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_SiteIncome_SalesMethod]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SalesMethod] DROP CONSTRAINT [FK_Rel_SiteIncome_SalesMethod];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_Dish_SaleStatus]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SaleStatus] DROP CONSTRAINT [FK_Rel_Dish_SaleStatus];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_SiteIncome_SaleStatus]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SaleStatus] DROP CONSTRAINT [FK_Rel_SiteIncome_SaleStatus];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_Site_SiteCost]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SiteCost] DROP CONSTRAINT [FK_Rel_Site_SiteCost];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_SiteCost_SiteCostItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SiteCostItem] DROP CONSTRAINT [FK_Rel_SiteCost_SiteCostItem];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_Supplier_SupplierContract]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SupplierContract] DROP CONSTRAINT [FK_Rel_Supplier_SupplierContract];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_Material_SupplierContractItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SupplierContractItem] DROP CONSTRAINT [FK_Rel_Material_SupplierContractItem];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_SupplierContract_SupplierContractItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SupplierContractItem] DROP CONSTRAINT [FK_Rel_SupplierContract_SupplierContractItem];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_Material_MaterialPurchaseItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MaterialPurchaseItem] DROP CONSTRAINT [FK_Rel_Material_MaterialPurchaseItem];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_MaterialPurchase_MaterialPurchaseItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MaterialPurchaseItem] DROP CONSTRAINT [FK_Rel_MaterialPurchase_MaterialPurchaseItem];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_Supplier_MaterialPurchase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MaterialPurchase] DROP CONSTRAINT [FK_Rel_Supplier_MaterialPurchase];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_MaterialProcess_MaterialProcessItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MaterialProcessItem] DROP CONSTRAINT [FK_Rel_MaterialProcess_MaterialProcessItem];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_RawMaterial_MaterialProcessItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MaterialProcessItem] DROP CONSTRAINT [FK_Rel_RawMaterial_MaterialProcessItem];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_SemiMaterial_MaterialProcessItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MaterialProcessItem] DROP CONSTRAINT [FK_Rel_SemiMaterial_MaterialProcessItem];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_Site_DishDelivery]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DishDelivery] DROP CONSTRAINT [FK_Rel_Site_DishDelivery];
GO
IF OBJECT_ID(N'[dbo].[FK_Rel_DishDelivery_DishDeliveryItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DishDeliveryItem] DROP CONSTRAINT [FK_Rel_DishDelivery_DishDeliveryItem];
GO
IF OBJECT_ID(N'[dbo].[FK_SemiMaterial_inherits_Material]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Material_SemiMaterial] DROP CONSTRAINT [FK_SemiMaterial_inherits_Material];
GO
IF OBJECT_ID(N'[dbo].[FK_RawMaterial_inherits_Material]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Material_RawMaterial] DROP CONSTRAINT [FK_RawMaterial_inherits_Material];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Material]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Material];
GO
IF OBJECT_ID(N'[dbo].[MaterialStorageHistory]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MaterialStorageHistory];
GO
IF OBJECT_ID(N'[dbo].[Dish]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Dish];
GO
IF OBJECT_ID(N'[dbo].[DishMaterial]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DishMaterial];
GO
IF OBJECT_ID(N'[dbo].[WeekDish]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WeekDish];
GO
IF OBJECT_ID(N'[dbo].[WeekDishItem]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WeekDishItem];
GO
IF OBJECT_ID(N'[dbo].[MaterialProcess]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MaterialProcess];
GO
IF OBJECT_ID(N'[dbo].[MaterialProcessItem]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MaterialProcessItem];
GO
IF OBJECT_ID(N'[dbo].[DishOrder]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DishOrder];
GO
IF OBJECT_ID(N'[dbo].[DishOrderItem]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DishOrderItem];
GO
IF OBJECT_ID(N'[dbo].[WeekDishOrder]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WeekDishOrder];
GO
IF OBJECT_ID(N'[dbo].[Site]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Site];
GO
IF OBJECT_ID(N'[dbo].[DishDelivery]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DishDelivery];
GO
IF OBJECT_ID(N'[dbo].[DishDeliveryItem]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DishDeliveryItem];
GO
IF OBJECT_ID(N'[dbo].[SiteIncome]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SiteIncome];
GO
IF OBJECT_ID(N'[dbo].[SalesMethod]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SalesMethod];
GO
IF OBJECT_ID(N'[dbo].[SaleStatus]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SaleStatus];
GO
IF OBJECT_ID(N'[dbo].[SiteCost]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SiteCost];
GO
IF OBJECT_ID(N'[dbo].[SiteCostItem]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SiteCostItem];
GO
IF OBJECT_ID(N'[dbo].[Supplier]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Supplier];
GO
IF OBJECT_ID(N'[dbo].[SupplierContract]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SupplierContract];
GO
IF OBJECT_ID(N'[dbo].[SupplierContractItem]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SupplierContractItem];
GO
IF OBJECT_ID(N'[dbo].[MaterialPurchase]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MaterialPurchase];
GO
IF OBJECT_ID(N'[dbo].[MaterialPurchaseItem]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MaterialPurchaseItem];
GO
IF OBJECT_ID(N'[dbo].[Dictionary]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Dictionary];
GO
IF OBJECT_ID(N'[dbo].[Material_SemiMaterial]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Material_SemiMaterial];
GO
IF OBJECT_ID(N'[dbo].[Material_RawMaterial]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Material_RawMaterial];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Material'
CREATE TABLE [dbo].[Material] (
    [ID] nvarchar(36)  NOT NULL,
    [Code] nvarchar(max)  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Unit] nvarchar(max)  NULL,
    [Specification] nvarchar(max)  NULL,
    [CurrentPrice] decimal(18,0)  NOT NULL,
    [SafeStorage] decimal(18,0)  NOT NULL,
    [ActualStorage] decimal(18,0)  NOT NULL,
    [Type] nvarchar(max)  NOT NULL,
    [IsDelete] bit  NOT NULL,
    [CreateAudit_Time] datetime  NOT NULL,
    [CreateAudit_UserCode] nvarchar(max)  NOT NULL,
    [CreateAudit_UserName] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_Time] datetime  NOT NULL,
    [LastUpdateAudit_UserCode] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_UserName] nvarchar(max)  NOT NULL,
    [Category] nvarchar(max)  NOT NULL,
    [Remark] nvarchar(max)  NULL
);
GO

-- Creating table 'MaterialStorageHistory'
CREATE TABLE [dbo].[MaterialStorageHistory] (
    [ID] nvarchar(36)  NOT NULL,
    [MaterialID] nvarchar(36)  NOT NULL,
    [Count] decimal(18,0)  NOT NULL,
    [Time] datetime  NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [Title] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Dish'
CREATE TABLE [dbo].[Dish] (
    [ID] nvarchar(36)  NOT NULL,
    [Code] nvarchar(max)  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Cost] decimal(18,0)  NOT NULL,
    [Price] decimal(18,0)  NOT NULL,
    [Category] nvarchar(max)  NOT NULL,
    [CookType] nvarchar(max)  NOT NULL,
    [IsDelete] bit  NOT NULL,
    [CreateAudit_Time] datetime  NOT NULL,
    [CreateAudit_UserCode] nvarchar(max)  NOT NULL,
    [CreateAudit_UserName] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_Time] datetime  NOT NULL,
    [LastUpdateAudit_UserCode] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_UserName] nvarchar(max)  NOT NULL,
    [MainMaterialCategory] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'DishMaterial'
CREATE TABLE [dbo].[DishMaterial] (
    [ID] nvarchar(36)  NOT NULL,
    [DishID] nvarchar(36)  NOT NULL,
    [MaterialID] nvarchar(36)  NOT NULL,
    [Weight] decimal(18,0)  NOT NULL
);
GO

-- Creating table 'WeekDish'
CREATE TABLE [dbo].[WeekDish] (
    [ID] nvarchar(36)  NOT NULL,
    [BeginDate] datetime  NOT NULL,
    [EndDate] datetime  NOT NULL,
    [CreateAudit_Time] datetime  NOT NULL,
    [CreateAudit_UserCode] nvarchar(max)  NOT NULL,
    [CreateAudit_UserName] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_Time] datetime  NOT NULL,
    [LastUpdateAudit_UserCode] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_UserName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'WeekDishItem'
CREATE TABLE [dbo].[WeekDishItem] (
    [ID] nvarchar(36)  NOT NULL,
    [DishID] nvarchar(36)  NOT NULL,
    [WeekDishID] nvarchar(36)  NOT NULL
);
GO

-- Creating table 'MaterialProcess'
CREATE TABLE [dbo].[MaterialProcess] (
    [ID] nvarchar(36)  NOT NULL,
    [Code] nvarchar(max)  NOT NULL,
    [ProcessDate] datetime  NOT NULL,
    [OrderState] nvarchar(max)  NOT NULL,
    [CreateAudit_Time] datetime  NOT NULL,
    [CreateAudit_UserCode] nvarchar(max)  NOT NULL,
    [CreateAudit_UserName] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_Time] datetime  NOT NULL,
    [LastUpdateAudit_UserCode] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_UserName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'MaterialProcessItem'
CREATE TABLE [dbo].[MaterialProcessItem] (
    [ID] nvarchar(36)  NOT NULL,
    [ExpectedPickCount] decimal(18,0)  NOT NULL,
    [ActualPickCount] decimal(18,0)  NULL,
    [ExpectedStorageCount] decimal(18,0)  NOT NULL,
    [ActualStorageCount] decimal(18,0)  NULL,
    [MaterialProcessID] nvarchar(36)  NOT NULL,
    [RawMaterialID] nvarchar(36)  NOT NULL,
    [SemiMaterialID] nvarchar(36)  NOT NULL
);
GO

-- Creating table 'DishOrder'
CREATE TABLE [dbo].[DishOrder] (
    [ID] nvarchar(36)  NOT NULL,
    [OrderDate] datetime  NOT NULL,
    [TotalCost] decimal(18,0)  NOT NULL,
    [TotalPrice] decimal(18,0)  NOT NULL,
    [OrderType] nvarchar(max)  NOT NULL,
    [SiteID] nvarchar(36)  NOT NULL,
    [WeekDishOrderID] nvarchar(36)  NULL,
    [OrderState] nvarchar(max)  NOT NULL,
    [CreateAudit_Time] datetime  NOT NULL,
    [CreateAudit_UserCode] nvarchar(max)  NOT NULL,
    [CreateAudit_UserName] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_Time] datetime  NOT NULL,
    [LastUpdateAudit_UserCode] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_UserName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'DishOrderItem'
CREATE TABLE [dbo].[DishOrderItem] (
    [ID] nvarchar(36)  NOT NULL,
    [DishID] nvarchar(36)  NULL,
    [Count] int  NOT NULL,
    [DishCost] decimal(18,0)  NOT NULL,
    [TotalCost] decimal(18,0)  NOT NULL,
    [DishName] nvarchar(max)  NOT NULL,
    [DishPrice] decimal(18,0)  NOT NULL,
    [TotalPrice] decimal(18,0)  NOT NULL,
    [DishOrderID] nvarchar(36)  NOT NULL
);
GO

-- Creating table 'WeekDishOrder'
CREATE TABLE [dbo].[WeekDishOrder] (
    [ID] nvarchar(36)  NOT NULL,
    [BeginDate] datetime  NOT NULL,
    [EndDate] datetime  NOT NULL,
    [SiteID] nvarchar(36)  NOT NULL,
    [OrderState] nvarchar(max)  NOT NULL,
    [CreateAudit_Time] datetime  NOT NULL,
    [CreateAudit_UserCode] nvarchar(max)  NOT NULL,
    [CreateAudit_UserName] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_Time] datetime  NOT NULL,
    [LastUpdateAudit_UserCode] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_UserName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Site'
CREATE TABLE [dbo].[Site] (
    [ID] nvarchar(36)  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Code] nvarchar(max)  NOT NULL,
    [SiteAddress] nvarchar(max)  NULL,
    [IsDelete] bit  NOT NULL,
    [CreateAudit_Time] datetime  NOT NULL,
    [CreateAudit_UserCode] nvarchar(max)  NOT NULL,
    [CreateAudit_UserName] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_Time] datetime  NOT NULL,
    [LastUpdateAudit_UserCode] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_UserName] nvarchar(max)  NOT NULL,
    [DeliveryAddress] nvarchar(max)  NULL,
    [PMName] nvarchar(max)  NULL,
    [ChefsName] nvarchar(max)  NULL,
    [AreaCode] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'DishDelivery'
CREATE TABLE [dbo].[DishDelivery] (
    [ID] nvarchar(36)  NOT NULL,
    [State] nvarchar(max)  NOT NULL,
    [Code] nvarchar(max)  NOT NULL,
    [Date] datetime  NOT NULL,
    [Address] nvarchar(max)  NOT NULL,
    [SiteID] nvarchar(36)  NOT NULL,
    [CreateAudit_Time] datetime  NOT NULL,
    [CreateAudit_UserCode] nvarchar(max)  NOT NULL,
    [CreateAudit_UserName] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_Time] datetime  NOT NULL,
    [LastUpdateAudit_UserCode] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_UserName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'DishDeliveryItem'
CREATE TABLE [dbo].[DishDeliveryItem] (
    [ID] nvarchar(36)  NOT NULL,
    [MaterialID] nvarchar(36)  NOT NULL,
    [DeliveryCount] decimal(18,0)  NULL,
    [SignCount] decimal(18,0)  NULL,
    [DishDeliveryID] nvarchar(36)  NOT NULL
);
GO

-- Creating table 'SiteIncome'
CREATE TABLE [dbo].[SiteIncome] (
    [ID] nvarchar(36)  NOT NULL,
    [SiteID] nvarchar(36)  NOT NULL,
    [Date] datetime  NOT NULL,
    [TotalAmount] decimal(18,0)  NULL,
    [State] nvarchar(max)  NOT NULL,
    [CreateAudit_Time] datetime  NOT NULL,
    [CreateAudit_UserCode] nvarchar(max)  NOT NULL,
    [CreateAudit_UserName] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_Time] datetime  NOT NULL,
    [LastUpdateAudit_UserCode] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_UserName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'SalesMethod'
CREATE TABLE [dbo].[SalesMethod] (
    [ID] nvarchar(36)  NOT NULL,
    [Type] nvarchar(max)  NOT NULL,
    [Amount] decimal(18,0)  NOT NULL,
    [SiteIncomeID] nvarchar(36)  NOT NULL
);
GO

-- Creating table 'SaleStatus'
CREATE TABLE [dbo].[SaleStatus] (
    [ID] nvarchar(36)  NOT NULL,
    [ProduceCount] int  NOT NULL,
    [SaleCount] int  NOT NULL,
    [RemainCount] int  NOT NULL,
    [DishName] nvarchar(max)  NOT NULL,
    [DishID] nvarchar(36)  NULL,
    [SiteIncomeID] nvarchar(36)  NOT NULL
);
GO

-- Creating table 'SiteCost'
CREATE TABLE [dbo].[SiteCost] (
    [ID] nvarchar(36)  NOT NULL,
    [BeginDate] datetime  NOT NULL,
    [EndDate] datetime  NOT NULL,
    [ExpectedCost] decimal(18,0)  NOT NULL,
    [ActualCost] decimal(18,0)  NULL,
    [SiteID] nvarchar(36)  NOT NULL,
    [State] nvarchar(max)  NOT NULL,
    [CreateAudit_Time] datetime  NOT NULL,
    [CreateAudit_UserCode] nvarchar(max)  NOT NULL,
    [CreateAudit_UserName] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_Time] datetime  NOT NULL,
    [LastUpdateAudit_UserCode] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_UserName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'SiteCostItem'
CREATE TABLE [dbo].[SiteCostItem] (
    [ID] nvarchar(36)  NOT NULL,
    [ExpectedCost] decimal(18,0)  NOT NULL,
    [ActualCost] decimal(18,0)  NULL,
    [ItemName] nvarchar(max)  NOT NULL,
    [SiteCostID] nvarchar(36)  NOT NULL
);
GO

-- Creating table 'Supplier'
CREATE TABLE [dbo].[Supplier] (
    [ID] nvarchar(36)  NOT NULL,
    [Code] nvarchar(max)  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Address] nvarchar(max)  NOT NULL,
    [IsDelete] bit  NOT NULL,
    [CreateAudit_Time] datetime  NOT NULL,
    [CreateAudit_UserCode] nvarchar(max)  NOT NULL,
    [CreateAudit_UserName] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_Time] datetime  NOT NULL,
    [LastUpdateAudit_UserCode] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_UserName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'SupplierContract'
CREATE TABLE [dbo].[SupplierContract] (
    [ID] nvarchar(36)  NOT NULL,
    [BeginDate] datetime  NOT NULL,
    [EndDate] datetime  NOT NULL,
    [Code] nvarchar(max)  NOT NULL,
    [SupplierID] nvarchar(36)  NOT NULL,
    [CreateAudit_Time] datetime  NOT NULL,
    [CreateAudit_UserCode] nvarchar(max)  NOT NULL,
    [CreateAudit_UserName] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_Time] datetime  NOT NULL,
    [LastUpdateAudit_UserCode] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_UserName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'SupplierContractItem'
CREATE TABLE [dbo].[SupplierContractItem] (
    [ID] nvarchar(36)  NOT NULL,
    [MaterialID] nvarchar(36)  NOT NULL,
    [Price] decimal(18,0)  NOT NULL,
    [SupplierContractID] nvarchar(36)  NOT NULL
);
GO

-- Creating table 'MaterialPurchase'
CREATE TABLE [dbo].[MaterialPurchase] (
    [ID] nvarchar(36)  NOT NULL,
    [SupplierID] nvarchar(36)  NOT NULL,
    [OrderDate] datetime  NOT NULL,
    [Code] nvarchar(max)  NOT NULL,
    [TotalPrice] decimal(18,0)  NOT NULL,
    [OrderState] nvarchar(max)  NOT NULL,
    [CreateAudit_Time] datetime  NOT NULL,
    [CreateAudit_UserCode] nvarchar(max)  NOT NULL,
    [CreateAudit_UserName] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_Time] datetime  NOT NULL,
    [LastUpdateAudit_UserCode] nvarchar(max)  NOT NULL,
    [LastUpdateAudit_UserName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'MaterialPurchaseItem'
CREATE TABLE [dbo].[MaterialPurchaseItem] (
    [ID] nvarchar(36)  NOT NULL,
    [MaterialID] nvarchar(36)  NOT NULL,
    [MaterialPurchaseID] nvarchar(36)  NOT NULL,
    [OrderCount] decimal(18,0)  NOT NULL,
    [DeliveryCount] decimal(18,0)  NULL,
    [StorageCount] decimal(18,0)  NULL,
    [Price] decimal(18,0)  NOT NULL
);
GO

-- Creating table 'Dictionary'
CREATE TABLE [dbo].[Dictionary] (
    [ID] nvarchar(36)  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Code] nvarchar(50)  NOT NULL,
    [TypeCode] nvarchar(50)  NULL,
    [Sequence] int  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [PingYinCode] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Material_SemiMaterial'
CREATE TABLE [dbo].[Material_SemiMaterial] (
    [RawMaterialID] nvarchar(36)  NOT NULL,
    [ProcessRate] decimal(18,0)  NOT NULL,
    [ID] nvarchar(36)  NOT NULL
);
GO

-- Creating table 'Material_RawMaterial'
CREATE TABLE [dbo].[Material_RawMaterial] (
    [ID] nvarchar(36)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Material'
ALTER TABLE [dbo].[Material]
ADD CONSTRAINT [PK_Material]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'MaterialStorageHistory'
ALTER TABLE [dbo].[MaterialStorageHistory]
ADD CONSTRAINT [PK_MaterialStorageHistory]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Dish'
ALTER TABLE [dbo].[Dish]
ADD CONSTRAINT [PK_Dish]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'DishMaterial'
ALTER TABLE [dbo].[DishMaterial]
ADD CONSTRAINT [PK_DishMaterial]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'WeekDish'
ALTER TABLE [dbo].[WeekDish]
ADD CONSTRAINT [PK_WeekDish]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'WeekDishItem'
ALTER TABLE [dbo].[WeekDishItem]
ADD CONSTRAINT [PK_WeekDishItem]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'MaterialProcess'
ALTER TABLE [dbo].[MaterialProcess]
ADD CONSTRAINT [PK_MaterialProcess]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'MaterialProcessItem'
ALTER TABLE [dbo].[MaterialProcessItem]
ADD CONSTRAINT [PK_MaterialProcessItem]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'DishOrder'
ALTER TABLE [dbo].[DishOrder]
ADD CONSTRAINT [PK_DishOrder]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'DishOrderItem'
ALTER TABLE [dbo].[DishOrderItem]
ADD CONSTRAINT [PK_DishOrderItem]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'WeekDishOrder'
ALTER TABLE [dbo].[WeekDishOrder]
ADD CONSTRAINT [PK_WeekDishOrder]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Site'
ALTER TABLE [dbo].[Site]
ADD CONSTRAINT [PK_Site]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'DishDelivery'
ALTER TABLE [dbo].[DishDelivery]
ADD CONSTRAINT [PK_DishDelivery]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'DishDeliveryItem'
ALTER TABLE [dbo].[DishDeliveryItem]
ADD CONSTRAINT [PK_DishDeliveryItem]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'SiteIncome'
ALTER TABLE [dbo].[SiteIncome]
ADD CONSTRAINT [PK_SiteIncome]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'SalesMethod'
ALTER TABLE [dbo].[SalesMethod]
ADD CONSTRAINT [PK_SalesMethod]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'SaleStatus'
ALTER TABLE [dbo].[SaleStatus]
ADD CONSTRAINT [PK_SaleStatus]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'SiteCost'
ALTER TABLE [dbo].[SiteCost]
ADD CONSTRAINT [PK_SiteCost]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'SiteCostItem'
ALTER TABLE [dbo].[SiteCostItem]
ADD CONSTRAINT [PK_SiteCostItem]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Supplier'
ALTER TABLE [dbo].[Supplier]
ADD CONSTRAINT [PK_Supplier]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'SupplierContract'
ALTER TABLE [dbo].[SupplierContract]
ADD CONSTRAINT [PK_SupplierContract]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'SupplierContractItem'
ALTER TABLE [dbo].[SupplierContractItem]
ADD CONSTRAINT [PK_SupplierContractItem]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'MaterialPurchase'
ALTER TABLE [dbo].[MaterialPurchase]
ADD CONSTRAINT [PK_MaterialPurchase]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'MaterialPurchaseItem'
ALTER TABLE [dbo].[MaterialPurchaseItem]
ADD CONSTRAINT [PK_MaterialPurchaseItem]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Dictionary'
ALTER TABLE [dbo].[Dictionary]
ADD CONSTRAINT [PK_Dictionary]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Material_SemiMaterial'
ALTER TABLE [dbo].[Material_SemiMaterial]
ADD CONSTRAINT [PK_Material_SemiMaterial]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Material_RawMaterial'
ALTER TABLE [dbo].[Material_RawMaterial]
ADD CONSTRAINT [PK_Material_RawMaterial]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [MaterialID] in table 'MaterialStorageHistory'
ALTER TABLE [dbo].[MaterialStorageHistory]
ADD CONSTRAINT [FK_Rel_Material_MaterialStorageHistory]
    FOREIGN KEY ([MaterialID])
    REFERENCES [dbo].[Material]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Material_MaterialStorageHistory'
CREATE INDEX [IX_FK_Rel_Material_MaterialStorageHistory]
ON [dbo].[MaterialStorageHistory]
    ([MaterialID]);
GO

-- Creating foreign key on [RawMaterialID] in table 'Material_SemiMaterial'
ALTER TABLE [dbo].[Material_SemiMaterial]
ADD CONSTRAINT [FK_Rel_RawMaterial_SemiMaterial]
    FOREIGN KEY ([RawMaterialID])
    REFERENCES [dbo].[Material_RawMaterial]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_RawMaterial_SemiMaterial'
CREATE INDEX [IX_FK_Rel_RawMaterial_SemiMaterial]
ON [dbo].[Material_SemiMaterial]
    ([RawMaterialID]);
GO

-- Creating foreign key on [DishID] in table 'DishMaterial'
ALTER TABLE [dbo].[DishMaterial]
ADD CONSTRAINT [FK_Rel_Dish_MaterialDish]
    FOREIGN KEY ([DishID])
    REFERENCES [dbo].[Dish]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Dish_MaterialDish'
CREATE INDEX [IX_FK_Rel_Dish_MaterialDish]
ON [dbo].[DishMaterial]
    ([DishID]);
GO

-- Creating foreign key on [MaterialID] in table 'DishMaterial'
ALTER TABLE [dbo].[DishMaterial]
ADD CONSTRAINT [FK_Rel_Material_DishMaterial]
    FOREIGN KEY ([MaterialID])
    REFERENCES [dbo].[Material]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Material_DishMaterial'
CREATE INDEX [IX_FK_Rel_Material_DishMaterial]
ON [dbo].[DishMaterial]
    ([MaterialID]);
GO

-- Creating foreign key on [DishID] in table 'WeekDishItem'
ALTER TABLE [dbo].[WeekDishItem]
ADD CONSTRAINT [FK_Rel_Dish_WeekDishItem]
    FOREIGN KEY ([DishID])
    REFERENCES [dbo].[Dish]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Dish_WeekDishItem'
CREATE INDEX [IX_FK_Rel_Dish_WeekDishItem]
ON [dbo].[WeekDishItem]
    ([DishID]);
GO

-- Creating foreign key on [WeekDishID] in table 'WeekDishItem'
ALTER TABLE [dbo].[WeekDishItem]
ADD CONSTRAINT [FK_WeekDishItemWeekDish]
    FOREIGN KEY ([WeekDishID])
    REFERENCES [dbo].[WeekDish]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WeekDishItemWeekDish'
CREATE INDEX [IX_FK_WeekDishItemWeekDish]
ON [dbo].[WeekDishItem]
    ([WeekDishID]);
GO

-- Creating foreign key on [DishID] in table 'DishOrderItem'
ALTER TABLE [dbo].[DishOrderItem]
ADD CONSTRAINT [FK_Rel_Dish_DishOrderItem]
    FOREIGN KEY ([DishID])
    REFERENCES [dbo].[Dish]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Dish_DishOrderItem'
CREATE INDEX [IX_FK_Rel_Dish_DishOrderItem]
ON [dbo].[DishOrderItem]
    ([DishID]);
GO

-- Creating foreign key on [DishOrderID] in table 'DishOrderItem'
ALTER TABLE [dbo].[DishOrderItem]
ADD CONSTRAINT [FK_Rel_DishOrder_DishOrderItem]
    FOREIGN KEY ([DishOrderID])
    REFERENCES [dbo].[DishOrder]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_DishOrder_DishOrderItem'
CREATE INDEX [IX_FK_Rel_DishOrder_DishOrderItem]
ON [dbo].[DishOrderItem]
    ([DishOrderID]);
GO

-- Creating foreign key on [SiteID] in table 'DishOrder'
ALTER TABLE [dbo].[DishOrder]
ADD CONSTRAINT [FK_Rel_Site_DishOrder]
    FOREIGN KEY ([SiteID])
    REFERENCES [dbo].[Site]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Site_DishOrder'
CREATE INDEX [IX_FK_Rel_Site_DishOrder]
ON [dbo].[DishOrder]
    ([SiteID]);
GO

-- Creating foreign key on [SiteID] in table 'WeekDishOrder'
ALTER TABLE [dbo].[WeekDishOrder]
ADD CONSTRAINT [FK_Rel_Site_WeekDishOrder]
    FOREIGN KEY ([SiteID])
    REFERENCES [dbo].[Site]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Site_WeekDishOrder'
CREATE INDEX [IX_FK_Rel_Site_WeekDishOrder]
ON [dbo].[WeekDishOrder]
    ([SiteID]);
GO

-- Creating foreign key on [WeekDishOrderID] in table 'DishOrder'
ALTER TABLE [dbo].[DishOrder]
ADD CONSTRAINT [FK_Rel_WeekDishOrder_DishOrder]
    FOREIGN KEY ([WeekDishOrderID])
    REFERENCES [dbo].[WeekDishOrder]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_WeekDishOrder_DishOrder'
CREATE INDEX [IX_FK_Rel_WeekDishOrder_DishOrder]
ON [dbo].[DishOrder]
    ([WeekDishOrderID]);
GO

-- Creating foreign key on [MaterialID] in table 'DishDeliveryItem'
ALTER TABLE [dbo].[DishDeliveryItem]
ADD CONSTRAINT [FK_Rel_DishDeliveryItem_Material]
    FOREIGN KEY ([MaterialID])
    REFERENCES [dbo].[Material]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_DishDeliveryItem_Material'
CREATE INDEX [IX_FK_Rel_DishDeliveryItem_Material]
ON [dbo].[DishDeliveryItem]
    ([MaterialID]);
GO

-- Creating foreign key on [SiteID] in table 'SiteIncome'
ALTER TABLE [dbo].[SiteIncome]
ADD CONSTRAINT [FK_Rel_Site_SiteIncome]
    FOREIGN KEY ([SiteID])
    REFERENCES [dbo].[Site]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Site_SiteIncome'
CREATE INDEX [IX_FK_Rel_Site_SiteIncome]
ON [dbo].[SiteIncome]
    ([SiteID]);
GO

-- Creating foreign key on [SiteIncomeID] in table 'SalesMethod'
ALTER TABLE [dbo].[SalesMethod]
ADD CONSTRAINT [FK_Rel_SiteIncome_SalesMethod]
    FOREIGN KEY ([SiteIncomeID])
    REFERENCES [dbo].[SiteIncome]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_SiteIncome_SalesMethod'
CREATE INDEX [IX_FK_Rel_SiteIncome_SalesMethod]
ON [dbo].[SalesMethod]
    ([SiteIncomeID]);
GO

-- Creating foreign key on [DishID] in table 'SaleStatus'
ALTER TABLE [dbo].[SaleStatus]
ADD CONSTRAINT [FK_Rel_Dish_SaleStatus]
    FOREIGN KEY ([DishID])
    REFERENCES [dbo].[Dish]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Dish_SaleStatus'
CREATE INDEX [IX_FK_Rel_Dish_SaleStatus]
ON [dbo].[SaleStatus]
    ([DishID]);
GO

-- Creating foreign key on [SiteIncomeID] in table 'SaleStatus'
ALTER TABLE [dbo].[SaleStatus]
ADD CONSTRAINT [FK_Rel_SiteIncome_SaleStatus]
    FOREIGN KEY ([SiteIncomeID])
    REFERENCES [dbo].[SiteIncome]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_SiteIncome_SaleStatus'
CREATE INDEX [IX_FK_Rel_SiteIncome_SaleStatus]
ON [dbo].[SaleStatus]
    ([SiteIncomeID]);
GO

-- Creating foreign key on [SiteID] in table 'SiteCost'
ALTER TABLE [dbo].[SiteCost]
ADD CONSTRAINT [FK_Rel_Site_SiteCost]
    FOREIGN KEY ([SiteID])
    REFERENCES [dbo].[Site]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Site_SiteCost'
CREATE INDEX [IX_FK_Rel_Site_SiteCost]
ON [dbo].[SiteCost]
    ([SiteID]);
GO

-- Creating foreign key on [SiteCostID] in table 'SiteCostItem'
ALTER TABLE [dbo].[SiteCostItem]
ADD CONSTRAINT [FK_Rel_SiteCost_SiteCostItem]
    FOREIGN KEY ([SiteCostID])
    REFERENCES [dbo].[SiteCost]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_SiteCost_SiteCostItem'
CREATE INDEX [IX_FK_Rel_SiteCost_SiteCostItem]
ON [dbo].[SiteCostItem]
    ([SiteCostID]);
GO

-- Creating foreign key on [SupplierID] in table 'SupplierContract'
ALTER TABLE [dbo].[SupplierContract]
ADD CONSTRAINT [FK_Rel_Supplier_SupplierContract]
    FOREIGN KEY ([SupplierID])
    REFERENCES [dbo].[Supplier]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Supplier_SupplierContract'
CREATE INDEX [IX_FK_Rel_Supplier_SupplierContract]
ON [dbo].[SupplierContract]
    ([SupplierID]);
GO

-- Creating foreign key on [MaterialID] in table 'SupplierContractItem'
ALTER TABLE [dbo].[SupplierContractItem]
ADD CONSTRAINT [FK_Rel_Material_SupplierContractItem]
    FOREIGN KEY ([MaterialID])
    REFERENCES [dbo].[Material]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Material_SupplierContractItem'
CREATE INDEX [IX_FK_Rel_Material_SupplierContractItem]
ON [dbo].[SupplierContractItem]
    ([MaterialID]);
GO

-- Creating foreign key on [SupplierContractID] in table 'SupplierContractItem'
ALTER TABLE [dbo].[SupplierContractItem]
ADD CONSTRAINT [FK_Rel_SupplierContract_SupplierContractItem]
    FOREIGN KEY ([SupplierContractID])
    REFERENCES [dbo].[SupplierContract]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_SupplierContract_SupplierContractItem'
CREATE INDEX [IX_FK_Rel_SupplierContract_SupplierContractItem]
ON [dbo].[SupplierContractItem]
    ([SupplierContractID]);
GO

-- Creating foreign key on [MaterialID] in table 'MaterialPurchaseItem'
ALTER TABLE [dbo].[MaterialPurchaseItem]
ADD CONSTRAINT [FK_Rel_Material_MaterialPurchaseItem]
    FOREIGN KEY ([MaterialID])
    REFERENCES [dbo].[Material]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Material_MaterialPurchaseItem'
CREATE INDEX [IX_FK_Rel_Material_MaterialPurchaseItem]
ON [dbo].[MaterialPurchaseItem]
    ([MaterialID]);
GO

-- Creating foreign key on [MaterialPurchaseID] in table 'MaterialPurchaseItem'
ALTER TABLE [dbo].[MaterialPurchaseItem]
ADD CONSTRAINT [FK_Rel_MaterialPurchase_MaterialPurchaseItem]
    FOREIGN KEY ([MaterialPurchaseID])
    REFERENCES [dbo].[MaterialPurchase]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_MaterialPurchase_MaterialPurchaseItem'
CREATE INDEX [IX_FK_Rel_MaterialPurchase_MaterialPurchaseItem]
ON [dbo].[MaterialPurchaseItem]
    ([MaterialPurchaseID]);
GO

-- Creating foreign key on [SupplierID] in table 'MaterialPurchase'
ALTER TABLE [dbo].[MaterialPurchase]
ADD CONSTRAINT [FK_Rel_Supplier_MaterialPurchase]
    FOREIGN KEY ([SupplierID])
    REFERENCES [dbo].[Supplier]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Supplier_MaterialPurchase'
CREATE INDEX [IX_FK_Rel_Supplier_MaterialPurchase]
ON [dbo].[MaterialPurchase]
    ([SupplierID]);
GO

-- Creating foreign key on [MaterialProcessID] in table 'MaterialProcessItem'
ALTER TABLE [dbo].[MaterialProcessItem]
ADD CONSTRAINT [FK_Rel_MaterialProcess_MaterialProcessItem]
    FOREIGN KEY ([MaterialProcessID])
    REFERENCES [dbo].[MaterialProcess]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_MaterialProcess_MaterialProcessItem'
CREATE INDEX [IX_FK_Rel_MaterialProcess_MaterialProcessItem]
ON [dbo].[MaterialProcessItem]
    ([MaterialProcessID]);
GO

-- Creating foreign key on [RawMaterialID] in table 'MaterialProcessItem'
ALTER TABLE [dbo].[MaterialProcessItem]
ADD CONSTRAINT [FK_Rel_RawMaterial_MaterialProcessItem]
    FOREIGN KEY ([RawMaterialID])
    REFERENCES [dbo].[Material_RawMaterial]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_RawMaterial_MaterialProcessItem'
CREATE INDEX [IX_FK_Rel_RawMaterial_MaterialProcessItem]
ON [dbo].[MaterialProcessItem]
    ([RawMaterialID]);
GO

-- Creating foreign key on [SemiMaterialID] in table 'MaterialProcessItem'
ALTER TABLE [dbo].[MaterialProcessItem]
ADD CONSTRAINT [FK_Rel_SemiMaterial_MaterialProcessItem]
    FOREIGN KEY ([SemiMaterialID])
    REFERENCES [dbo].[Material_SemiMaterial]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_SemiMaterial_MaterialProcessItem'
CREATE INDEX [IX_FK_Rel_SemiMaterial_MaterialProcessItem]
ON [dbo].[MaterialProcessItem]
    ([SemiMaterialID]);
GO

-- Creating foreign key on [SiteID] in table 'DishDelivery'
ALTER TABLE [dbo].[DishDelivery]
ADD CONSTRAINT [FK_Rel_Site_DishDelivery]
    FOREIGN KEY ([SiteID])
    REFERENCES [dbo].[Site]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_Site_DishDelivery'
CREATE INDEX [IX_FK_Rel_Site_DishDelivery]
ON [dbo].[DishDelivery]
    ([SiteID]);
GO

-- Creating foreign key on [DishDeliveryID] in table 'DishDeliveryItem'
ALTER TABLE [dbo].[DishDeliveryItem]
ADD CONSTRAINT [FK_Rel_DishDelivery_DishDeliveryItem]
    FOREIGN KEY ([DishDeliveryID])
    REFERENCES [dbo].[DishDelivery]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rel_DishDelivery_DishDeliveryItem'
CREATE INDEX [IX_FK_Rel_DishDelivery_DishDeliveryItem]
ON [dbo].[DishDeliveryItem]
    ([DishDeliveryID]);
GO

-- Creating foreign key on [ID] in table 'Material_SemiMaterial'
ALTER TABLE [dbo].[Material_SemiMaterial]
ADD CONSTRAINT [FK_SemiMaterial_inherits_Material]
    FOREIGN KEY ([ID])
    REFERENCES [dbo].[Material]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ID] in table 'Material_RawMaterial'
ALTER TABLE [dbo].[Material_RawMaterial]
ADD CONSTRAINT [FK_RawMaterial_inherits_Material]
    FOREIGN KEY ([ID])
    REFERENCES [dbo].[Material]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------